package org.itydl.game.model

import org.itheima.kotlin.game.core.Composer
import org.itheima.kotlin.game.core.Painter
import org.itydl.game.Config
import org.itydl.game.business.Attackable
import org.itydl.game.business.Blockable
import org.itydl.game.business.Destoryable
import org.itydl.game.business.Sufferable

/**
 * 模型类
 * 砖墙，面向对象思想
 * 墙、草坪、水、坦克都是绘制到窗体上的，公共：位置参数、自身宽高、行为（例如：绘制功能）
 */
class Wall(override val x: Int, override val y: Int) :
        Blockable, Sufferable, Destoryable {// 阻挡能力，遭受打击能力，销毁能力

    /**
     * 墙的血值是3（攻击者攻击3次才具备销毁能力）
     */
    override var blood: Int = 3

    /**
     * 宽高
     */
    override val width: Int = Config.block
    override val height: Int = Config.block

    /**
     * 行为
     */
    override fun draw() {
        Painter.drawImage("img/wall.gif", x, y)
    }

    /**
     * 遭受了攻击者攻击
     * 被攻击者生命值减少
     */
    override fun notifySuffered(attackable: Attackable): Array<View>? {
        blood -= attackable.power
        // 遭受打击，给与反馈
        // 喊疼
        Composer.play("snd/hit.wav")
        return arrayOf(Blast(x, y))
    }

    override fun isDestory(): Boolean {
        if (blood <= 0) {
            return true
        }
        return false
    }
}